package com.hns.can.master.service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hns.can.master.vo.FullDateVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 公交首页service
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class HomeTransitWholeService extends CommonService {
	@Autowired
	private TendencyChartsDataTools tendencyChartsDataTools;	//趋势图补充数据工具

	private List<String> singleFuncType = Arrays.asList(new String[]{"energyTendencyChart"});
	private List<String> multiFuncType = Arrays.asList(new String[]{"initSafetyTendencyChart"});
	/**
	 * 加载公交首页数据
	 * @param map	参数
	 * @param funcType 功能类型
	 * @param className	转化类型名称
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List<T> getHomeData(Map<String, Object> map, String funcType, String className) throws Exception{
		Class<?> clazz = Class.forName("com.hns.can.master.vo."+className);
//		try{
//			list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("homeTransit."+funcType, map), clazz);
//		}catch(Exception e){
//			e.printStackTrace();
//		}
		List list = null;
		try{
			list = this.sqlMapDao.selectList("homeTransit."+funcType, map);
		}catch(Exception e){
			System.out.println("================================================================================="+funcType);
		}
		if(multiFuncType.contains(funcType) && PubUtil.isNotEmpty(list)){
			list = tendencyChartsDataTools.fillSafetyMultiTendencyData(list, (String)map.get("dateType"));
		}else if(singleFuncType.contains(funcType) && PubUtil.isNotEmpty(list)){
			list = tendencyChartsDataTools.fillEnergySingleTendencyData(list, (String)map.get("dateType"));
		}
		list = PubUtil.convertListMapToObject(list, clazz);
		return list;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> loadMaintenanceEvent(Map<String, Object> map) {
		//1.通过维保明细查询出维保计划
		List<Map<String, Object>> list = this.sqlMapDao.selectList("homeTransit.getMaintenEventList", map);
		return list;
	}


	@SuppressWarnings("unchecked")
	public List<T> getFullDate(Map<String, Object> map) {
		List<T> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("homeTransit.getFullDate", map), FullDateVo.class);
		return list;
	}
	
}
